package com.zhang.log4j2desensitization.config;


import java.util.HashMap;
import java.util.Map;

/**
 * 拦截脱敏的日志:
 * 1，身份证
 * 2，姓名
 * 3，身份证号 （目前暂时不脱敏）
 * 4、地址
 * 脱敏规则后续可以优化在配置文件中
 *
 **/
public class Log4j2Rule {

    /**
     * 正则匹配 关键词 类别
     */
    public static Map<String, String> regularMap = new HashMap<>();
    /**
     * TODO  可配置
     * 此项可以后期放在配置项中
     */
    public static final String USER_NAME_STR = "customerName,userName,user,paymentUserName,order_contacts_name";
    public static final String USER_ADDRESS_STR = "receiveAddress,address,order_address";
    //暂时不需要脱敏身份证
//    public static final String USER_IDCARD_STR = "empCard,idCard";
    public static final String USER_PHONE_STR = "mobile,phone,contactPhone,customerTelephone,customerLinkPhone,memberPhone,phoneNumber,mealPhone,order_contacts_phone,from,to";

    /**
     * 正则匹配，根据业务要求自定义
     */
//    private static final String IDCARD_REGEXP = "(\\d{17}[0-9Xx]|\\d{14}[0-9Xx])";
    private static final String USERNAME_REGEXP = "[\\u4e00-\\u9fa5_a-zA-Z0-9-]{2,50}";
    private static final String ADDRESS_REGEXP = "[\\u4e00-\\u9fa5_a-zA-Z0-9-]{3,200}";
    private static final String PHONE_REGEXP = "(?<!\\d)(?:(?:1[3456789]\\d{9})|(?:861[356789]\\d{9}))(?!\\d)";

    static {
        regularMap.put(USER_NAME_STR, USERNAME_REGEXP);
        regularMap.put(USER_ADDRESS_STR, ADDRESS_REGEXP);
//        regularMap.put(USER_IDCARD_STR, IDCARD_REGEXP);
        regularMap.put(USER_PHONE_STR, PHONE_REGEXP);
    }

}
